package com.example.aslongastoday.db.helper;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 该类本质上是定义了和回忆录相关的数据库，并用于创建和管理回忆录相关的表
 * 至于对这个数据库中的表的具体的CRUD的操作，则应该在具体的DAO类中去实现
 */

public class MemoryDatabaseHelper extends SQLiteOpenHelper {
    public static final String DATABASE_NAME = "memory.db";
    public static final int DATABASE_VERSION = 1;
    public static final String TABLE_NAME = "memory";
    public static final String COLUMN_ID = "id";
    public static final String COLUMN_TIME = "time";
    public static final String COLUMN_NAME = "name";
    public static final String COLUMN_IS_ANNIVERSARY = "is_anniversary";
    public static final String COLUMN_ICON_INDEX = "icon_index";
    public static final String COLUMN_MESSAGE = "message";

    private static final String CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + " (" +
                    COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                    COLUMN_TIME + " TEXT, " +
                    COLUMN_NAME + " TEXT, " +
                    COLUMN_IS_ANNIVERSARY + " INTEGER, " +
                    COLUMN_ICON_INDEX + " INTEGER, " +
                    COLUMN_MESSAGE + " TEXT)";

    public MemoryDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists "+TABLE_NAME);
        onCreate(db);
    }
}
